var basePath = "http://127.0.0.1:8080/cms2";

$(document).on("keypress", function (e) {
    if (e.keyCode == 13) {
        return false;
    }
})

//校验成功
function success_status($obj, value) {
    $obj.parents(".form-group").removeClass("has-error has-success").addClass("has-success");
    $obj.nextAll(".glyphicon").remove();
    $obj.next(".help-block").text("");
    $obj.after($("<span class='glyphicon glyphicon-ok form-control-feedback' aria-hidden='true'></span>"));
    if (arguments.length == 2) {
        $obj.val(value);
    }
}

//校验失败
function error_status($obj, helpText) {
    $obj.parents(".form-group").removeClass("has-error has-success").addClass("has-error");
    $obj.nextAll(".glyphicon").remove();
    $obj.next(".help-block").text(helpText);
    $obj.after($("<span class='glyphicon glyphicon-remove form-control-feedback' aria-hidden='true'></span>"));
}

//去除验证 设置提示及值
function clear_status($obj, help, value) {
    //1、设置信息
    $obj.nextAll(".help-block").text(help);
    //2 form-group div  去除has-success has-error类名
    $obj.parents(".form-group").removeClass("has-success has-error");
    //3 去除图标
    $obj.nextAll(".glyphicon").remove();
    if (arguments.length == 3) {
        $obj.val(value);
    }
}

//去除所有校验状态
function resetValid() {
    $(".has-feedback").removeClass("has-success has-error");
    $(".has-feedback").find(".glyphicon").remove();
    $(".has-feedback").find(".help-block").text("");
}


//共用方法，比较对象属性值发生变化 true
function isChangeObj(old_obj, new_obj) {
    var flag = false;
    $.each(new_obj, function (name, value) {
        if (old_obj[name] != value) {
            flag = true;
            return false;
        }
    })
    return flag;
}
